package com.zyj.config;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.context.annotation.Import;
import org.springframework.core.convert.support.ConfigurableConversionService;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import javax.annotation.Resource;

@Configuration
// 不扫描 @Controller 注解
@ComponentScan(basePackages = "com.zyj",
    excludeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION, classes = {Controller.class})})
// 扫描 @Mapper 注解
@MapperScan(basePackages = "com.zyj.mapper")
@EnableTransactionManagement
@Import({DataSourceConfig.class, SpringMvcConfig.class})
public class SpringConfig extends WebMvcConfigurationSupport {

    @Resource
    private ConfigurableConversionService conversionService;

    public SpringConfig() {
        System.out.println("应用启动……");
    }

    // 配置 multipart 类型解析器, 图片上传等
    @Bean
    public MultipartResolver multipartResolver() {
        CommonsMultipartResolver resolver = new CommonsMultipartResolver();
        resolver.setDefaultEncoding("utf-8");
        resolver.setMaxUploadSize(50 * 1024 * 1024);
        resolver.setMaxInMemorySize(40 * 1024 * 1024);
        return resolver;
    }
}
